﻿#Include g:\AHK\git-ahk-lib\Extend.ahk
#Include g:\AHK\git-ahk-lib\util\Animation.ahk
#Include g:\AHK\git-ahk-lib\Theme.ahk

#SingleInstance Force

Esc:: ExitApp
OnMessage(0x0201, (*) => PostMessage(0xA1, 2))

t := A_Args.Length ? A_Args[1] = 'dark' ? Color.Dark() : Color.Light() : Random(1, 10) > 5 ? Color.Dark() : Color.Light()

x := 17, text := [], s := 18
g := Gui('+AlwaysOnTop +ToolWindow -Caption +Border')
g.SetFont('s14', 'consolas')
g.AddText('Section w220 yp+35 h1 Backgroundb3a700')
g.AddText('yp ym x+3 w20 h15', '·').OnEvent('ContextMenu', End)
g.SetFont('s12')

; #region
AddRow5('a', ['あ3', 'いe', 'う4', 'え5', 'お6'])
AddRow5('k', ['かt', 'きg', 'くh', 'け`'', 'こb'])
AddRow5('s', ['さx', 'しd', 'すr', 'せp', 'そc'])
AddRow5('t', ['たq', 'ちa', 'つz', 'てw', 'とs'])
AddRow5('n', ['なu', 'にi', 'ぬ1', 'ね,', 'のk'])
AddRow5('h', ['はf', 'ひv', 'ふ2', 'へ=', 'ほ-'])
AddRow5('m', ['まj', 'みn', 'む\', 'め/', 'もm'])
AddRow3('y', ['や7', 'ゆ8', 'よ9'])
AddRow5('r', ['らo', 'りl', 'る.', 'れ;', 'ろ``'])
AddRow5('w', ['わ0', ', ', 'を0', '. ', 'んy'])
; #endregion

End(*) {
  for v in text
    r .= v.Text
  IsSet(r) && A_Clipboard := r
  Animation.RollUp(g), ExitApp()
}
AddCh(ch) {
  c := g.AddText(Format('Background{} x{} w12 y13 c{}', t.rb, x, t.rt), ch)
  text.Push(c)
  c.OnEvent('ContextMenu', (*) => _clear(c))
  global x += s
  _clear(c) {
    c.Visible := false, x -= s
    i := text.findIndex(v => v = c)
    loop text.Length - i {
      text[A_Index + i].GetPos(&x)
      text[A_Index + i].Move(x - s)
    }
    text.RemoveAt(i)
  }
}
class Color {
  class Light {
    rt := '0e4800'
    rb := 'ebe5cb'
    r0 := 'e0d9be'
    r1 := 'e0e6c6'
    r2 := 'e6e4c6'
    r3 := 'd7e6c6'
    r4 := 'e6e4c6'
    r5 := 'e2e6c6'
    r9 := 'e6e4c6'
    r8 := 'e6e4c6'
    r7 := 'e6e4c6'
  }
  class Dark {
    rt := '1be562'
    rb := '262721'
    r0 := '282922'
    r1 := '3b3d33'
    r2 := '383730'
    r3 := '393d35'
    r4 := '383730'
    r5 := '393a31'
    r9 := '383730'
    r8 := '383730'
    r7 := '383730'
  }
}
AddRow5(r, ch) {
  g.AddText('Section Background' t.r1 ' xs w35', ch[1]).OnEvent('ContextMenu', (c, *) => AddCh(KeyPressed() ? c.text[2] : c.Text[1]))
  g.AddText('yp w35 Background' t.r2, ch[2]).OnEvent('ContextMenu', (c, *) => AddCh(c.Text[1]))
  g.AddText('yp w35 Background' t.r3, ch[3]).OnEvent('ContextMenu', (c, *) => AddCh(c.Text[1]))
  g.AddText('yp w35 Background' t.r4, ch[4]).OnEvent('ContextMenu', (c, *) => AddCh(c.Text[1]))
  g.AddText('yp w35 Background' t.r5, ch[5]).OnEvent('ContextMenu', (c, *) => AddCh(c.Text[1]))
  g.AddText('yp w5 x3', r)
}
AddRow3(r, ch) {
  g.AddText('Section xs w35 Background' t.r9, ch[1]).OnEvent('ContextMenu', (c, *) => AddCh(c.Text[1]))
  g.AddText('yp xp+92 w35 Background' t.r8, ch[2]).OnEvent('ContextMenu', (c, *) => AddCh(c.Text[1]))
  g.AddText('yp xp+92  w35 Background' t.r7, ch[3]).OnEvent('ContextMenu', (c, *) => AddCh(c.Text[1]))
  g.AddText('yp w5 x3', r)
}
(t is Color.Dark) ? Theme.Dark(g) : Theme.Light(g)
g.SetFont('s14')
Animation.RollDown(g, Noop, (*) => g.Move(A_ScreenWidth / 2 - 105, A_ScreenHeight - 360, 257))
WinSetTransColor('white', g), FrameShadow(g.Hwnd)
FrameShadow(hwnd) {
  bf := Buffer(4), NumPut('uint', -1, bf)
  DllCall("dwmapi\DwmSetWindowAttribute", "ptr", hwnd, "uint", 2, "int*", 2, "uint", 4)
  DllCall("dwmapi\DwmExtendFrameIntoClientArea", "ptr", hwnd, "ptr", bf)
}

KeyPressed() => GetKeyState('LShift', 'P')